import axios from 'axios'
import { Message } from 'element-ui'

//http://192.168.31.103:8080/shopping/sortList
const service = axios.create({
  baseURL: 'http://120.48.178.250:8004/', 
  timeout: 5000 ,
  withCredentials: false // 表示跨域请求时是否需要使用凭证
})

// 请求拦截器
service.interceptors.request.use(
  config => {

    return config
  },
  error => {
    // do something with request error
    console.log(error) 
    return Promise.reject(error)
  }
)

// 响应拦截器
service.interceptors.response.use(

  response => {
    return response.data
  },
  error => {
    console.log('err' + error)
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)

export function post(url,data) {
   return service({
    url,
    data,
    method: 'post', 
   })
}

export function get(url,params) {
    return service({
     url,
     params,
     method: 'get', 
    })
 }

